<template>
  <div class="address-box page" ref="webview">
    <van-nav-bar title="收货地址" class="bg_grey" left-arrow @click-left="$router.go(-1)" />
    <div class="content" v-if="dataList.length>0">
      <van-pull-refresh v-model="isLoading" @refresh="onRefresh" style="height:100%">
        <van-list v-model="loading" :finished="finished" :finished-text="dataList.length>7?'没有更多了':''" @load="onLoad" :offset="50" :immediate-check="false" v-if="dataList.length>0">
          <template v-for="(item,index) in dataList">
            <div class="list van-hairline-j--top" @click="goDetails(item)" :key="index">
              <div class="info">
                <div class="name">
                  <span class="is_default" v-if="item.is_default">默</span>
                  {{item.name}} {{item.mobile | phoneFilter}}</div>
                <p class="address-info">{{item.prov_name}}{{item.city_name}}{{item.area_name}} {{item.address}}</p>
              </div>
              <div class="edit" v-if="$route.query.type !== 'order'">
                <span class="icon-address-edit"></span>
              </div>
            </div>
          </template>
        </van-list>
      </van-pull-refresh>
    </div>
    <div class="address-add" @click="goAdd">新增地址</div>
  </div>
</template>
<script>
import mixins from '@/utils/mixins';
export default {
  name: 'addressList',
  data () {
    return {
      paramsUrl: 'list',
      apiType: 'user',
      apiUrl: 'address'
    };
  },
  mixins: [mixins],
  created () {
    this.getList('address', true);
  },
  mounted () {

  },
  methods: {
    goDetails (item) {
      if (this.$route.query.type !== 'order') {
        this.$router.push({ 'path': '/address/sub/edit', query: { id: item.id } });
      } else {
        sessionStorage.setItem('address', JSON.stringify(item));
        this.$router.go(-1);
      }
    },
    goAdd () {
      this.$router.push({ 'path': '/address/sub/add' });
    }
  }
};
</script>
<style lang="less" scoped>
.address-box {
  display: flex;
  flex-direction: column;
  .content {
    flex: 1;
    overflow: auto;
    box-sizing: border-box;
    .list {
      display: flex;
      padding: 33px 0 33px 40px;
      background-color: #fff;
    }

    .info {
      flex: 1;
      .name {
        vertical-align: middle;
        .is_default {
          text-align: center;
          width: 50px;
          margin: 0 10px 0 0;
          color: #fff;
          background-color: #ff0034;
          padding: 5px;
          font-size: 30px;
          border-radius: 50px;
          line-height: 40px;
          display: inline-block;
          height: 50px;
        }
        color: #353535;
        font-size: 34px;
      }
      .address-info {
        font-size: 28px;
        padding-top: 20px;
        color: #353535;
      }
    }
    .edit {
      display: flex;
      width: 120px;
      align-items: center;
      justify-content: center;
      .icon-address-edit {
        display: block;
        width: 30px;
        height: 36px;
        background-image: url('/static/images/icon-address-edit.png');
        background-position: center center;
        background-repeat: no-repeat;
        background-size: contain;
      }
    }
  }
  .address-add {
    color: #ff0034;
    font-size: 32px;
    text-align: center;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    bottom: calc(1px + env(safe-area-inset-bottom));
    &::before {
      content: '+';
      display: inline-block;
      font-size: 40px;
      margin-top: -5px;
      margin-right: 10px;
    }
  }
}
</style>
